using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;

/// <summary>
/// Summary description for ClsCustomer
/// </summary>
/// 

    public class ClsCustomer
    {

        private string cnstr = ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString;
        private string sql;

        public ClsCustomer()
        {
            //
            // TODO: Add constructor logic here
            //
        }

        public void Insert(string CustomerName, string Gender, string City, string State, string CustomerType)
        {
            string sql = "Insert Into Customer (Name, Gender, City, State, Type) Values ('" + CustomerName
                + "' , '" + Gender + "', '" + City + "', '" + State + "', '" + CustomerType + "')";
            SqlConnection conn = new SqlConnection(cnstr);
            conn.Open();
            SqlCommand cmd = new SqlCommand(sql, conn);
            cmd.ExecuteNonQuery();
            conn.Close();
            conn.Dispose();
        }

        public DataTable Fetch()
        {
            string sql = "Select * From Customer";
            SqlDataAdapter da = new SqlDataAdapter(sql, cnstr);
            DataTable dt = new DataTable();
            da.Fill(dt);
            return dt;
        }



        public void Update(int CustomerCode, string CustomerName, string Gender, string City, string CustomerType)
        {
            string sql = "UPDATE Customer SET Name='" + CustomerName + "', Gender = '" + Gender
                + "', City='" + City + "', Type = '" + CustomerType + "' Where Code=" + CustomerCode;
            SqlConnection conn = new SqlConnection(cnstr);
            conn.Open();
            SqlCommand cmd = new SqlCommand(sql, conn);
            cmd.ExecuteNonQuery();
            conn.Close();
            conn.Dispose();
        }

        public void Delete(int CustomerCode)
        {
            string sql = "Delete Customer Where Code=" + CustomerCode;
            SqlConnection conn = new SqlConnection(cnstr);
            conn.Open();
            SqlCommand cmd = new SqlCommand(sql, conn);
            cmd.ExecuteNonQuery();
            conn.Close();
            conn.Dispose();
        }

        public DataTable FetchCustomerType()
        {
            string sql = "Select Distinct Type From Customer";
            SqlDataAdapter da = new SqlDataAdapter(sql, cnstr);
            DataTable dt = new DataTable();
            da.Fill(dt);
            return dt;
        }


    }
